﻿using Architecture.CrossCutting.LoggingEntities;
using Architecture.CrossCutting.Web.Tracing.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.OData;
using System.Web.OData.Builder;
using System.Web.OData.Extensions;
using System.Web.OData.Query;

namespace Architecture.Presentation.WebApiServices2.Controllers
{
    public class WebApiLogsController : ODataController
    {

        LoggingServiceContext ctx = new LoggingServiceContext();


        [EnableQuery(AllowedQueryOptions=AllowedQueryOptions.All)]
        public IQueryable<WebApiLog> Get()
        {
            //ODataModelBuilder builder = new ODataConventionModelBuilder();
            //builder.EntitySet<WebApiLog>("WebApiLogs");

            //var queryOption = new ODataQueryOptions<WebApiLog>(
            //new ODataQueryContext(builder.GetEdmModel(),

            return ctx.WebApiLogs;
        }

        [EnableQuery]
        public SingleResult<WebApiLog> Get([FromODataUri] String key)
        {
            IQueryable<WebApiLog> result = ctx.WebApiLogs.Where(p => p.Id == Guid.Parse(key));
            return SingleResult.Create(result);
        }


        protected override void Dispose(bool disposing)
        {
            ctx.Dispose();
            base.Dispose(disposing);
        }
   }
}